//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GaussHyperbolicIntegration.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#include <gen/QL/Math/Array.h>
#include <gen/QL/Math/Integrals/GaussianQuadrature.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (UInt64 n) : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussHyperbolicIntegration = NULL;
#endif
        QuantLib::Size _n = (QuantLib::Size)ValueHelper::Convert (n); //d
        _ppGaussHyperbolicIntegration = new boost::shared_ptr<QuantLib::GaussHyperbolicIntegration> (new QuantLib::GaussHyperbolicIntegration ( _n ));
        SetGaussianQuadrature (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (boost::shared_ptr<QuantLib::GaussHyperbolicIntegration>& childNative, Object^ owner) : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
#ifdef HANDLE
	_phGaussHyperbolicIntegration = NULL;
#endif
	_ppGaussHyperbolicIntegration = &childNative;
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
}
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (QuantLib::GaussHyperbolicIntegration& childNative, Object^ owner) : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
#ifdef HANDLE
	_phGaussHyperbolicIntegration = NULL;
#endif
	_ppGaussHyperbolicIntegration = new boost::shared_ptr<QuantLib::GaussHyperbolicIntegration> (&childNative);
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
    _GaussHyperbolicIntegrationOwner = owner;
    _GaussianQuadratureOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (CGaussHyperbolicIntegration^ copy) : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
#ifdef HANDLE
	_phGaussHyperbolicIntegration = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussHyperbolicIntegration = new boost::shared_ptr<QuantLib::GaussHyperbolicIntegration> (copy->GetShared());
        _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
    }
}
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (PLATFORM::Type^ t) : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
#ifdef HANDLE
	_phGaussHyperbolicIntegration = NULL;
#endif
	if (!t->IsSubclassOf(CGaussHyperbolicIntegration::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (QuantLib::Handle<QuantLib::GaussHyperbolicIntegration>& childNative, Object^ owner)  : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
	_phGaussHyperbolicIntegration = &childNative;
	_ppGaussHyperbolicIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussHyperbolicIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
    _GaussHyperbolicIntegrationOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (QuantLib::Handle<QuantLib::GaussHyperbolicIntegration> childNative)  : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
	_phGaussHyperbolicIntegration = &childNative;
	_ppGaussHyperbolicIntegration = &static_cast<boost::shared_ptr<QuantLib::GaussHyperbolicIntegration>>(childNative.currentLink());
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::CGaussHyperbolicIntegration (QuantLib::GaussHyperbolicIntegration childNative)  : CGaussianQuadrature(CGaussHyperbolicIntegration::typeid)
{
#ifdef HANDLE
	_phGaussHyperbolicIntegration = NULL;
#endif
	_ppGaussHyperbolicIntegration = new boost::shared_ptr<QuantLib::GaussHyperbolicIntegration> (new QuantLib::GaussHyperbolicIntegration (childNative));
    _ppGaussianQuadrature = new boost::shared_ptr<QuantLib::GaussianQuadrature> (boost::dynamic_pointer_cast<QuantLib::GaussianQuadrature> (*_ppGaussHyperbolicIntegration));
}
#endif

Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::~CGaussHyperbolicIntegration ()
{
    if (_ppGaussHyperbolicIntegration != NULL)
    {
	    delete _ppGaussHyperbolicIntegration;
        _ppGaussHyperbolicIntegration = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::!CGaussHyperbolicIntegration ()
{
    if (_ppGaussHyperbolicIntegration != NULL)
    {
	    delete _ppGaussHyperbolicIntegration;
    }
}
QuantLib::GaussHyperbolicIntegration& Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::GetReference ()
{
    if (_ppGaussHyperbolicIntegration == NULL) throw REFNEW NativeNullException ();
	return **_ppGaussHyperbolicIntegration;
}
boost::shared_ptr<QuantLib::GaussHyperbolicIntegration>& Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::GetShared ()
{
    if (_ppGaussHyperbolicIntegration == NULL) throw REFNEW NativeNullException ();
	return *_ppGaussHyperbolicIntegration;
}
QuantLib::GaussHyperbolicIntegration* Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::GetPointer ()
{
    if (_ppGaussHyperbolicIntegration == NULL) throw REFNEW NativeNullException ();
	return &**_ppGaussHyperbolicIntegration;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussHyperbolicIntegration>& Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::GetHandle ()
{
	if (_phGaussHyperbolicIntegration == NULL)
	{
		_phGaussHyperbolicIntegration = new Handle<QuantLib::GaussHyperbolicIntegration> (*_ppGaussHyperbolicIntegration);
	}
	return *_phGaussHyperbolicIntegration;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration::HasNative () 
{
	return (_ppGaussHyperbolicIntegration != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussHyperbolicIntegration^ Cephei::QL::Math::Integrals::CGaussHyperbolicIntegration_Factory::Create (UInt64 n)
{
    return REFNEW CGaussHyperbolicIntegration ( n);
}
